﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HideAndSeek
{
    class Opponent
    {
        private Location myLocation;
        private Random random;
        public Opponent(Location myLocation)
        {
            this.myLocation = myLocation;

            random = new Random();
        }
        public void Move()
        {
            bool hidden = false;
            while (!hidden)
            {

                if (myLocation is IHasExteriorDoor)
                {
                    if (random.Next(2) == 0)
                    {
                        IHasExteriorDoor myLocationWithDoor = myLocation as IHasExteriorDoor;
                        myLocation = myLocationWithDoor.DoorLocation;
                    }
                }

                int ran = random.Next(myLocation.Exits.Length);
                myLocation = myLocation.Exits[ran];
                if (myLocation is IHidingPlace) { hidden = true; }

            }

            
        }
        public bool Check(Location locationToCheck)
        {
            if (locationToCheck != myLocation)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
